import axios from 'axios'
import {Toast} from "vant";

const service = axios.create({
    baseURL: process.env.VUE_APP_BASE_API, // api 的 base_url
    timeout: 5000 // request timeout
})

axios.defaults.withCredentials = true

// request interceptor
// service.interceptors.request.use(
//     config => {
//         return config;
//     },
//     err => Promise.reject(err)
// )

// request interceptor
service.interceptors.response.use (
    response=> {
        if(response.code === 500) {
            Toast.fail('服务器内部错误')
        } else if (response.code === 404) {
            Toast.fail('页面未找到')
        } else if (response.data.code !== 200) {
            Toast.fail(response.data.message)
        }
        return response
    }
)
export default service
